home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Draw / Sources / RRectShp.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  7.4 KB  |  277 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RRectShp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef RRECTSHP_H
  23. #include "RRectShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. // ----- Foundation Includes -----
  107.  
  108. #ifndef FWSTREAM_H
  109. #include "FWStream.h"
  110. #endif
  111.  
  112. // ----- OpenDoc Includes -----
  113.  
  114. #ifndef SOM_ODTransform_xh
  115. #include <Trnsform.xh>
  116. #endif
  117.  
  118. //========================================================================================
  119. // Runtime Information
  120. //========================================================================================
  121.  
  122. #ifdef FW_BUILD_MAC
  123. #pragma segment odfdrawshapes
  124. #endif
  125.  
  126. //========================================================================================
  127. // RunTime Info
  128. //========================================================================================
  129.  
  130. FW_DEFINE_AUTO(CRoundRectShape)
  131. FW_DEFINE_CLASS_M1(CRoundRectShape, CBoundedShape)
  132.  
  133. const FW_ClassTypeConstant LRoundRectShape = FW_TYPE_CONSTANT('s','h','r','r');
  134. FW_REGISTER_ARCHIVABLE_CLASS(LRoundRectShape, CRoundRectShape, CRoundRectShape::Read, 0, 0, CBaseShape::Write)
  135.  
  136. //========================================================================================
  137. // class CRoundRectShape
  138. //========================================================================================
  139.  
  140. //----------------------------------------------------------------------------------------
  141. // CRoundRectShape::CRoundRectShape
  142. //----------------------------------------------------------------------------------------
  143.  
  144. CRoundRectShape::CRoundRectShape():
  145.     CBoundedShape(kRRectShape, kFrameOnly),
  146.     fOvalSize(FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(32)))
  147. {
  148.     FW_END_CONSTRUCTOR
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. // CRoundRectShape::CRoundRectShape
  153. //----------------------------------------------------------------------------------------
  154.  
  155. CRoundRectShape::CRoundRectShape(FW_CReadableStream& archive) :
  156.     CBoundedShape(archive)
  157. {    
  158.     archive >> fOvalSize;
  159.     FW_END_CONSTRUCTOR
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. // CRoundRectShape::~CRoundRectShape
  164. //----------------------------------------------------------------------------------------
  165.  
  166. CRoundRectShape::~CRoundRectShape()
  167. {
  168.     FW_START_DESTRUCTOR
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // CRoundRectShape::OutlineShape
  173. //----------------------------------------------------------------------------------------
  174.  
  175. void CRoundRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  176. {
  177.     FW_CRect bounds(rect);
  178.     AdjustRectForPenSize(bounds, style.GetPenSize());
  179.     FW_CRoundRectShape::RenderRoundRect(gc,
  180.                                       bounds,
  181.                                     fOvalSize,
  182.                                       FW_kFrame,
  183.                                       ink, style);
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. // CRoundRectShape::RenderShape
  188. //----------------------------------------------------------------------------------------
  189.  
  190. void CRoundRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  191. {
  192.     FW_CRect rect = GetRectGeometry();
  193.     AdjustRectForPenSize(rect, GetPenSize());
  194.  
  195.     if (HasFillStyle())
  196.         FW_CRoundRectShape::RenderRoundRect(gc, rect, fOvalSize, FW_kFill, fFillInk, fFillStyle);
  197.     
  198.     if (HasFrameStyle())
  199.         FW_CRoundRectShape::RenderRoundRect(gc, rect, fOvalSize, FW_kFrame, fFrameInk, fFrameStyle);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // CRoundRectShape::HitTest
  204. //----------------------------------------------------------------------------------------
  205.  
  206. FW_Boolean CRoundRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  207. {    
  208.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  209.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  210.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  211.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  212.  
  213.     FW_CRect bounds = GetRectGeometry();
  214.     AdjustRectForPenSize(bounds, GetPenSize());
  215.  
  216.     FW_CRoundRectShape RRectShape(bounds, fOvalSize, HasFillStyle() ? FW_kFill : FW_kFrame);
  217.     return RRectShape.HitTest(gc, mouse, FW_IntToFixed(2));
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. // CRoundRectShape::GetClipRegion
  222. //----------------------------------------------------------------------------------------
  223.  
  224. void CRoundRectShape::GetClipRegion(Environment* ev, ODShape* clipRegion)
  225. {
  226.     FW_CRect bounds = GetRectGeometry();
  227.     AdjustRectForPenSize(bounds, GetPenSize());
  228.     
  229.     ODShape* roundRectShape = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);
  230.     clipRegion->CopyFrom(ev, roundRectShape);
  231.     roundRectShape->Release(ev);
  232.     
  233.     if (FrameOnly())
  234.     {
  235.         bounds.Inset(GetPenSize(), GetPenSize());
  236.         roundRectShape = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);
  237.         clipRegion->Subtract(ev, roundRectShape);
  238.         roundRectShape->Release(ev);
  239.     }
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // CRoundRectShape::CreateShapeOutline
  244. //----------------------------------------------------------------------------------------
  245.  
  246. ODShape* CRoundRectShape::CreateShapeOutline(Environment *ev)
  247. {
  248.     FW_CRect bounds = GetRectGeometry();
  249.     AdjustRectForPenSize(bounds, GetPenSize());
  250.     
  251.     ODShape* dragRgn = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);        // We don't acquire it because we return it
  252.     
  253.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  254.     
  255.     return dragRgn;
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. // CRoundRectShape::Read
  260. //----------------------------------------------------------------------------------------
  261.  
  262. void* CRoundRectShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  263. {
  264. FW_UNUSED(type);
  265.     return FW_NEW(CRoundRectShape, (stream));
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. // CRoundRectShape::Flatten
  270. //----------------------------------------------------------------------------------------
  271.  
  272. void CRoundRectShape::Flatten(FW_CWritableStream& archive)
  273. {    
  274.     CBoundedShape::Flatten(archive);
  275.     archive << fOvalSize;
  276. }
  277.